//
//  ZFBBusinessTypeView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/3/31.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "ZFBBusinessTypeView.h"
#import "ZFBBusinessTypeLayout.h"
#import "ZFBBusinessTypeModel.h"
#import "GGZFBBusinessCollectionViewCell.h"
#import "GGAutoCollectionHeaderView.h"
#import "GGAutoCollectionFooterView.h"
static NSString *cellID = @"cellID";
static NSString *footerCellID = @"footerCellID";
static NSString *headerCellID = @"headerCellID";
@interface ZFBBusinessTypeView ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@end

@implementation ZFBBusinessTypeView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    ZFBBusinessTypeLayout *layout = [[ZFBBusinessTypeLayout alloc]init];
    //设置组头组尾的高度
    layout.headerReferenceSize = CGSizeMake(CGRectGetWidth(self.frame), 20);
    layout.footerReferenceSize = CGSizeMake(CGRectGetWidth(self.frame), 20);
    //设置组头组尾固定
//    layout.sectionHeadersPinToVisibleBounds = YES;
//    layout.sectionFootersPinToVisibleBounds = YES;
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)) collectionViewLayout:layout];
    [self addSubview:collectionView];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.showsVerticalScrollIndicator = NO;
    [collectionView registerClass:[GGZFBBusinessCollectionViewCell class] forCellWithReuseIdentifier:cellID];
    //注册组头组尾
//    [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerCellID];
    [collectionView registerClass:[GGAutoCollectionHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerCellID];
//    [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footerCellID];
    [collectionView registerClass:[GGAutoCollectionFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:footerCellID];
    collectionView.dataSource = self;
}

- (void)setBusinessTypeModelList:(NSMutableArray<ZFBBusinessTypeModel *> *)businessTypeModelList{
    _businessTypeModelList = businessTypeModelList;
}
//- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
//    return 2;
//}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _businessTypeModelList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    GGZFBBusinessCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    cell.model = _businessTypeModelList[indexPath.item];
    return cell;
}
#pragma mark - 自定义组头组尾
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if([kind isEqualToString:UICollectionElementKindSectionFooter]){
     //组尾
//        UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:footerCellID forIndexPath:indexPath];
//        footerView.backgroundColor = [UIColor redColor];
        GGAutoCollectionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:footerCellID forIndexPath:indexPath];
        return footerView;
    }
//    UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerCellID forIndexPath:indexPath];
//    headerView.backgroundColor = [UIColor blueColor];
    GGAutoCollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headerCellID forIndexPath:indexPath];
    return headerView;
}


@end
